<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qquickdrawer.cpp -->
  <title>Drawer QML Type | Qt Quick Controls 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtquickcontrols-index.html">Qt Quick Controls</a></td><td ><a href="qtquick-controls2-qmlmodule.html">QML Types</a></td><td >Drawer QML Type</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquickcontrols-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#properties">属性</a></li>
<li class="level1"><a href="#details">详细描述</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QML的Drawer（抽屉）类型</h1>
<span class="subtitle"></span>
<!-- $$$Drawer-brief -->
<p>侧板，可以通过滑动手势打开或关闭。<a href="#details">更多… </a></p>
<!-- @@@Drawer -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> import QtQuick.Controls 2.5</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 5.7</td></tr><tr><td class="memItemLeft rightAlign topAlign">继承自：</td><td class="memItemRight bottomAlign"> <p><a href="qml-qtquick-controls2-popup.html">Popup</a></p>
</td></tr></table></div><ul>
<li><a href="qml-qtquick-controls2-drawer-members.html">所有成员的列表，包括继承的成员。</a></li>
</ul>
<a name="properties"></a>
<h2 id="properties">属性</h2>
<ul>
<li class="fn"><b><b><a href="qml-qtquick-controls2-drawer.html#dragMargin-prop">dragMargin</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qtquick-controls2-drawer.html#edge-prop">edge</a></b></b> : enumeration</li>
<li class="fn"><b><b><a href="qml-qtquick-controls2-drawer.html#interactive-prop">interactive</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-qtquick-controls2-drawer.html#position-prop">position</a></b></b> : real</li>
</ul>
<!-- $$$Drawer-description -->
<a name="details"></a>
<h2 id="details">详细描述</h2>
<p>Drawer提供了一个基于滑动的侧板，类似于那些经常用于触摸界面的侧板，该侧板为导航提供了一个集中位置。</p>
<p class="centerAlign"><img src="images/qtquickcontrols2-drawer.gif" alt="" /></p><p>Drawer项可以定位于内容项的任意四个边。上图中的抽屉靠窗的左边。然后把抽屉从窗口的左边缘<i>&quot;拖&quot;</i> 出来打开。</p>
<pre class="cpp">

  import <span class="type">QtQuick</span> <span class="number">2.12</span>
  import <span class="type">QtQuick</span><span class="operator">.</span>Controls <span class="number">2.12</span>

  ApplicationWindow {
      id: window
      visible: <span class="keyword">true</span>

      Drawer {
          id: drawer
          width: <span class="number">0.66</span> <span class="operator">*</span> window<span class="operator">.</span>width
          height: window<span class="operator">.</span>height

          Label {
              text: <span class="string">&quot;Content goes here!&quot;</span>
              anchors<span class="operator">.</span>centerIn: parent
          }
      }
  }

</pre>
<p>Drawer是一种特殊类型的弹出窗口，位于窗口的一个<a href="qml-qtquick-controls2-drawer.html#edge-prop">edges</a>。默认情况下，Drawer项将自己重设为窗口<a href="qml-qtquick-controls2-applicationwindow-obsolete.html#overlay-attached-prop">overlay（覆盖）</a>的，从而对窗口坐标进行操作。 还可以手动将<a href="qml-qtquick-controls2-popup.html#parent-prop">parent（父）</a> 类设置为其他值，以使Drawer项在特定的坐标空间中运行。</p>
<p>Drawer可以配置为只覆盖其窗口边缘的一部分。下面的示例演示了如何将折叠项定位为显示在窗口标题下面:</p>
<pre class="cpp">

  import <span class="type">QtQuick</span> <span class="number">2.12</span>
  import <span class="type">QtQuick</span><span class="operator">.</span>Controls <span class="number">2.12</span>

  ApplicationWindow {
      id: window
      visible: <span class="keyword">true</span>

      header: ToolBar { }

      Drawer {
          y: header<span class="operator">.</span>height
          width: window<span class="operator">.</span>width <span class="operator">*</span> <span class="number">0.6</span>
          height: window<span class="operator">.</span>height <span class="operator">-</span> header<span class="operator">.</span>height
      }
  }

</pre>
<p><a href="qml-qtquick-controls2-drawer.html#position-prop">position</a>属性确定抽屉的可见程度，其值介于<code>0.0</code> 和 <code>1.0</code>之间。无法将抽屉的x坐标(或水平边距)设置在窗口的左右边缘，也无法将抽屉的y坐标(或垂直边距)设置在窗口的上下边缘。</p>
<p>在上图中，应用程序的内容被<i>&quot;推送&quot;</i>到屏幕上。这是通过对内容应用翻译实现的:</p>
<pre class="cpp">

  import <span class="type">QtQuick</span> <span class="number">2.12</span>
  import <span class="type">QtQuick</span><span class="operator">.</span>Controls <span class="number">2.12</span>

  ApplicationWindow {
      id: window
      width: <span class="number">200</span>
      height: <span class="number">228</span>
      visible: <span class="keyword">true</span>

      Drawer {
          id: drawer
          width: <span class="number">0.66</span> <span class="operator">*</span> window<span class="operator">.</span>width
          height: window<span class="operator">.</span>height
      }

      Label {
          id: content

          text: <span class="string">&quot;Aa&quot;</span>
          font<span class="operator">.</span>pixelSize: <span class="number">96</span>
          anchors<span class="operator">.</span>fill: parent
          verticalAlignment: Label<span class="operator">.</span>AlignVCenter
          horizontalAlignment: Label<span class="operator">.</span>AlignHCenter

          transform: Translate {
              x: drawer<span class="operator">.</span>position <span class="operator">*</span> content<span class="operator">.</span>width <span class="operator">*</span> <span class="number">0.33</span>
          }
      }
  }

</pre>
<p>如果您希望应用程序的内容在抽屉打开时保持原样，则不要使用翻译功能。</p>
<p>通过使Drawer项<a href="qml-qtquick-controls2-popup.html#modal-prop">非模态</a> 和<a href="qml-qtquick-controls2-drawer.html#interactive-prop">非交互式</a>，可以将Drawer项配置为非封闭的持久侧面板。有关详细信息，请参阅 <a href="qtquickcontrols-sidepanel-example.html">侧面板</a>示例。</p>
<p><b>注意: </b>在某些平台上，某些边可能被保留为系统手势，因此不能与Drawer一起使用。例如，顶部和底部边缘可以预留给Android和iOS上的系统通知和控制中心。</p><p><b参见</b><a href="qml-qtquick-controls2-swipeview.html">SwipeView</a>, <a href="qtquickcontrols2-customize.html#customizing-drawer">定制的Drawer</a>, <a href="qtquickcontrols2-navigation.html">导航控件</a>以及 <a href="qtquickcontrols2-popups.html">弹出控件</a>。</p>
<!-- @@@Drawer -->
<h2>属性的文档</h2>
<!-- $$$dragMargin -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="dragMargin-prop">
<td class="tblQmlPropNode"><p>
<a name="dragMargin-prop"></a><span class="name">dragMargin</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>此属性保存从屏幕边缘到拖动操作将打开Drawer项的屏幕边缘的距离。将值设置为<code>0</code>或更小，可以防止通过拖动打开抽屉。</p>
<p>默认值是 <code>Qt.styleHints.startDragDistance</code>。</p>
<p><b>参见</b><a href="qml-qtquick-controls2-drawer.html#interactive-prop">interactive（交互）</a>。</p>
</div></div><!-- @@@dragMargin -->
<br/>
<!-- $$$edge -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="edge-prop">
<td class="tblQmlPropNode"><p>
<a name="edge-prop"></a><span class="name">edge</span> : <span class="type"><a href="../qtqml/qml-enumeration.html">enumeration</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>此属性保存抽屉被放在哪个边缘。可接受的数值为:</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>Qt.TopEdge</code></td><td class="topAlign">窗户的上边缘。</td></tr>
<tr><td class="topAlign"><code>Qt.LeftEdge</code></td><td class="topAlign">窗口的左边缘(默认)。</td></tr>
<tr><td class="topAlign"><code>Qt.RightEdge</code></td><td class="topAlign">窗户的右边。</td></tr>
<tr><td class="topAlign"><code>Qt.BottomEdge</code></td><td class="topAlign">窗户的底边。</td></tr>
</table></div>
</div></div><!-- @@@edge -->
<br/>
<!-- $$$interactive -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="interactive-prop">
<td class="tblQmlPropNode"><p>
<a name="interactive-prop"></a><span class="name">interactive</span> : <span class="type"><a href="../qtqml/qml-bool.html">bool</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>此属性保存抽屉是否具有交互性。非交互式抽屉不会对滑动做出反应。</p>
<p>默认值为<code>true</code>。</p>
<p>这个属性是在 QtQuick.Controls 2.2 (Qt 5.9)中引入的。</p>
<p><b>参见</b><a href="qml-qtquick-controls2-drawer.html#dragMargin-prop">dragMargin</a>。/p>
</div></div><!-- @@@interactive -->
<br/>
<!-- $$$position -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="position-prop">
<td class="tblQmlPropNode"><p>
<a name="position-prop"></a><span class="name">position</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>此属性保存抽屉相对于其最终目的地的位置。当抽屉完全关闭时的位置为<code>0.0</code>0.0，完全打开时的位置为<code>1.0</code>。</p>
</div></div><!-- @@@position -->
<br/>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
